home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2454 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1002 b   |  31 lines

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointer Conversion
  5. Date: 21 Jan 1996 12:44:37 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4dtu25$bgu@umbc9.umbc.edu>
  8. References: <4ds4jq$fo4@su3.in.net> <4ds6s3$ft6@su3.in.net>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. Sam Pounds <poundss@in.net> wrote:
  13. |> Sorry, it just dawned on me.
  14. |> char *done = (char *)malloc(1024);
  15. |> 
  16. |> But if anyone could tell me how I could just alloc the
  17. |> necessary memory for the two pointers I would appreciate it.
  18. |> Sorry again.
  19.  
  20. Well drop the unnecessary cast while making sure you #include <stdlib.h>.
  21. Then do:
  22.  
  23. char *done = malloc (strlen (a) + strlen (b) + 1);
  24.  
  25. That will give you only as much space as you need with no room to spare.
  26. Make sure you verify that malloc() does not return NULL.
  27. -- 
  28. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  29.  
  30. Jonas J. Schlein  (schlein@gl.umbc.edu)
  31.